package timer;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Ming on 2017/6/3.
 */
public class WaterRobot extends TimerTask {
    private Timer timer;
    private Integer bucketCapacity = 0;
    public WaterRobot(Timer inputTimer){
        timer = inputTimer;
    }
    @Override
    public void run() {
        if(bucketCapacity < 5){
            System.out.println("add water");
            bucketCapacity ++;
        }else {
            cancel();
            System.out.println("wr stop");
            System.out.println(timer.purge());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            timer.cancel();
        }
    }
}
